package com.spider.silence.main;

import com.spider.silence.downloader.YiBinZeroJuLiDownLoader;
import com.spider.silence.pool.YiBinZeroJuLiLoaderPool;
import com.spider.silence.utils.PropertiesUtil;
import com.spider.silence.worker.YiBinZeroJuLiWoker;
import org.apache.log4j.PropertyConfigurator;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by qiuhao on 2017/3/28.
 */
public class YiBinZeroJuLiMain {

    public static void main(String[] args) throws  Exception{
        PropertyConfigurator.configure( PropertiesUtil.getLogPro());
        YiBinZeroJuLiLoaderPool downLoaderPool= YiBinZeroJuLiLoaderPool.getInstance();
        YiBinZeroJuLiDownLoader downLoader=downLoaderPool.fetchDownLoader(1000);
        List<String> urlList=downLoader.getModulesUrlList();
        downLoader.generateTask(urlList);
//      downLoader.generateAllTask(urlList);
        ExecutorService pool =  Executors.newFixedThreadPool(Integer.valueOf(PropertiesUtil.getVal("main.woker.size")));
        for(int i = 0; i<Integer.valueOf(PropertiesUtil.getVal("YiBinZeroJuLi.WorkerCount")); i++){
           pool.execute(new YiBinZeroJuLiWoker());
       }
//       JSONObject content=downLoader.crawlItem("http://bbs.ybvv.com/thread-1097780-1-1.html");
//        MongoWriter writer=new MongoWriter();
//        writer.write("qiuhao","test", JSON.toJSONString(content, SerializerFeature.BrowserCompatible));
//       System.out.println(content);

    }
}
